//
//  DefaultValue.swift
//  ChinaPoem-Swift
//
//  Created by jh on 2022/12/15.
//

import Foundation

@propertyWrapper
struct UserDefault<T> {
    private var key: String
    private var defaultValue: T
    var wrappedValue: T {
        get { UserDefaults.standard.object(forKey: key) as? T ?? defaultValue }
        set { UserDefaults.standard.set(newValue, forKey: key)}
    }
    
    init(_ key: String, defaultValue: T) {
        self.key = key
        self.defaultValue = defaultValue
    }
}

struct AppUserDefaults {
    @UserDefault("user_region", defaultValue: Locale.current.regionCode ?? "US")
    static var region: String
        
    @UserDefault("original_title", defaultValue: false)
    static var alwaysOriginalTitle: Bool
}
